<template>
  <view>
    <view v-for="item in dataList" :key="item.id">
      <view style="margin-top: 10rpx;color: #000;" v-if="item.showName">{{ item.name }}</view>
      <up-input style="margin-top: 10rpx;" size="small" v-model="item.value" :disabled="true"
        :customStyle="{ width: '83vw' }"></up-input>
    </view>
  </view>
</template>

<script>
import org from '@/apis/cloud/org.js'
export default {
  name: 'BasicData',
  props: {
    propsitem: {
      type: Object,
      default: () => {
        return {}
      }
    },
    title: {
      type: String,
      default: ''
    },
    ApplyDetailList: {
      type: Array,
      default: () => {
        return []
      }
    },
    options: {
      type: Array,
      default: () => {
        return []
      }
    },
    itemId: {
      type: String,
      required: true
    },
    source: {
      type: Number,
      default: 1
    }
  },
  data () {
    return {
      dataList: [], // 表单数据
    }
  },
  watch: {
    dataList: {
      handler (newValue) {
        let value = uni.getStorageSync('formData');
        var formItems = JSON.parse(value.formItems);
        formItems.forEach(item => {
          if (item.title == this.title) {
            uni.setStorageSync(item.id, newValue);
          }
        })
      },
      deep: true
    }
  },
  created () {
    this.getList()
  },
  methods: {
    async getList () {
      let res = await org.getCurrentData({ type: this.source })
      if (res.status == 1) {
        this.options.map(e => {
          switch (e.id) {
            case 1:
              this.dataList.push({
                'name': e.newName,
                'showName': e.showName,
                'value': res.data.worker_name,
                'id': res.data.worker_id
              });
              break;
            case 2:
              this.dataList.push({
                'name': e.newName,
                'showName': e.showName,
                'value': res.data.depart_name,
                'id': res.data.worker_id
              });
              break;
            case 3:
              this.dataList.push({
                'name': e.newName,
                'showName': e.showName,
                'value': res.data.pos_name,
                'id': res.data.worker_id
              });
              break;
            case 4:
              this.dataList.push({
                'name': e.newName,
                'showName': e.showName,
                'value': res.data.entry_date,
                'id': res.data.worker_id
              });
              break;
          }
        })
      }

      console.log('this.dataList', this.dataList);

    }
  }
}
</script>

<style scoped lang="sass">

</style>